package genericdemo;

import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-10-29
 * Time: 10:04
 */
class Alg<E extends Comparable<E>>{
    public E findMax(E[] array){
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) <0 ){
                max = array[i];
            }

        }
        return max;
    }
}
class Alg2 {
    public <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }

        }
        return max;
    }
}
class Alg3 {
    public static <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 0; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }

        }
        return max;
    }
}

    class A<E extends Number> {

    }

    public class Test2_1 {
        public static void main(String[] args) {
            Integer[] array = {1, 4, 2, 5, 10, 9, 8, 16};
            Integer val = Alg3.findMax(array);
            System.out.println(val);
        }
        public static void main3(String[] args) {
            Alg2 alg2 = new Alg2();
            Integer[] array = {1, 4, 2, 5, 10, 9, 8, 16};
            Integer val = alg2.findMax(array);
            System.out.println(val);

        }


        public static void main2(String[] args) {
            A<Number> a1 = new A<>();
            A<Integer> a2 = new A<>();
            A<Double> a3 = new A<>();

        }

        public static void main1(String[] args) {
            Alg<Integer> alg = new Alg<>();
            Integer[] array = {1, 4, 2, 5, 10, 9, 8, 16};
            Integer val = alg.findMax(array);
            System.out.println(val);
        }
    }

